import { Injectable } from '@angular/core';
import { HttpClientService } from '../http/http-client.service';
import { HttpMethod } from '../http/http-method';
import { RESTfulResult } from '../http/restful-result.type';
import { ProvinceType } from "../model/province.type";
import { CityType } from "../model/city.type";
import { DistrictType } from "../model/district.type";
import { AreaType } from "../model/area.type";

@Injectable()
export class QueryService {

	constructor(
		private http: HttpClientService,
	) {
	}

	/** getAllProvinces */
	public getAllProvinces(): Promise<RESTfulResult<Array<ProvinceType>>> {
		return this.http.request({
			method: HttpMethod.GET,
			url: '/query/getAllProvinces',
			data: null,
		})
	}

	/** getCitiesByProvinceAdcode */
	public getCitiesByProvinceAdcode(data: { adcode: string }): Promise<RESTfulResult<Array<CityType>>> {
		return this.http.request({
			method: HttpMethod.GET,
			url: '/query/getCitiesByProvinceAdcode',
			data: data,
		})
	}

	/** getDistrictsByCityAdcode */
	public getDistrictsByCityAdcode(data: { adcode: string }): Promise<RESTfulResult<Array<DistrictType>>> {
		return this.http.request({
			method: HttpMethod.GET,
			url: '/query/getDistrictsByCityAdcode',
			data: data,
		})
	}

	/** getAreaByAdcode */
	public getAreaByAdcode(data: { adcode: string }): Promise<RESTfulResult<AreaType>> {
		return this.http.request({
			method: HttpMethod.GET,
			url: '/query/getAreaByAdcode',
			data: data,
		})
	}

}
